//
//  ZMColor.m
//  基本框架
//
//  Created by runone02 on 2018/6/28.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

#import "ZMColor.h"

@implementation ZMColor

+ (UIColor *)colorWithRed:(CGFloat)red withGtrrn:(CGFloat)green withBlue:(CGFloat)blub withAlpha:(CGFloat)alpha{
    return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blub/255.0 alpha:alpha];
}


+ (UIColor *)colorWithHexString:(NSString *)color alpha:(CGFloat)alpha{
    //删除字符串中的空格
    NSString *cstring = [[color stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]uppercaseString];
    if ([cstring length] < 6) {
        return [UIColor clearColor];
    }
    
     //如果是0x开头的，那么截取字符串，字符串从索引为2的位置开始，一直到末尾
    if ([cstring hasPrefix:@"0X"]) {
        cstring = [cstring substringFromIndex:2];
    }
    
    if ([cstring hasPrefix:@"#"]) {
        cstring = [cstring substringFromIndex:1];
    }
    
    if ([cstring length] != 6) {
        return [UIColor clearColor];
    }
    
    NSRange range;
    
    range.location = 0;
    range.length = 2;
    //r
    NSString *rString = [cstring substringWithRange:range];
    //g
    range.location = 2;
    NSString *gString = [cstring substringWithRange:range];
    
    range.location = 4;
    NSString *Bstring = [cstring substringWithRange:range];
    
    unsigned int r, g, b;
    
    [[NSScanner scannerWithString:rString] scanHexInt:&r];
    [[NSScanner scannerWithString:gString]scanHexInt:&g];
    [[NSScanner scannerWithString:Bstring]scanHexInt:&b];
    
    return [UIColor colorWithRed:((float)r / 255.0f) green:((float)g / 255.0f) blue:((float)b / 255.0f) alpha:alpha];
}

+ (UIColor *) colorWithHexString:(NSString *)color{
    return [self colorWithHexString:color alpha:1.0f];
}

+ (UIColor *) clearColor{
    return  [UIColor clearColor];
}

+ (UIColor *) whiteColor {
    return [UIColor whiteColor];
}

+(UIColor *) blackColor {
    return [UIColor blackColor];
}

+ (UIColor *) appMainColor {
    return [self colorWithHexString:@"#00DA8C"];
}

+ (UIColor *) appNavTitleGrayColor{
    return [UIColor colorWithRed:113/255.0 green:113/255.0 blue:113/255.0 alpha:1];
}

+ (UIColor *)appGraySpaceColor{
    return [self colorWithHexString:@"#f4f4f4" alpha:1.0f];
}

+ (UIColor *)appSubColor{
    return [self colorWithHexString:@"#333333" alpha:1.0f];
}

+ (UIColor *) appSupportColor{
    return  [self colorWithHexString:@"#999999" alpha:1.0f];
}

+(UIColor *) appLinghtGrayColor{
    return [self colorWithHexString:@"#D2D2D2" alpha:1.0f];
}
+(UIColor *) appSubBlueColor{
    return [self colorWithHexString:@"#7EC1FB" alpha:1.0f];
}

+ (UIColor *)appBottomLineColor{
    return  [self colorWithHexString:@"#DCDCDC" alpha:1.0f];
}
@end
